package com.dw.etl.core.controller;

import javax.servlet.http.HttpServletRequest;

import com.dw.etl.common.base.BaseException;
import com.dw.etl.core.bean.vo.EtlIndexShowVO;
import com.dw.etl.core.bean.vo.EtlIndexSqlVO;
import org.springframework.beans.factory.annotation.Autowired;
import  com.dw.etl.common.base.BaseResult;
import  com.dw.etl.common.constant.CommonResultConstant;
import com.dw.etl.core.api.EtlIndexsqlService;
import com.dw.etl.core.bean.model.EtlIndexsql;
import org.springframework.util.StringUtils;
import  com.dw.etl.common.vo.PaginationVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * etlIndexsql控制器
 * Created by hozeData on 2021/07/13.
 */
@RestController
@RequestMapping("/etl/etlIndexsql/")
@Api(tags="开发中")
@CrossOrigin(origins = "*", maxAge = 3600)
public class EtlIndexsqlController {

    @Autowired
    EtlIndexsqlService etlIndexsqlService;

    @ApiOperation(value="分页查询")
    @RequestMapping(value="findByPage", method=RequestMethod.POST)
    public BaseResult findByPage(@RequestBody EtlIndexsql etlIndexsql, Integer pageNum, Integer pageSize) {
        PaginationVO<EtlIndexsql> pageVO = etlIndexsqlService.findPageByModel(etlIndexsql, pageNum, pageSize);
        return new BaseResult(CommonResultConstant.SUCCESS, pageVO);
    }

    @ApiOperation(value="根据指标主键查询")
    @RequestMapping(value="getByIndex", method=RequestMethod.GET)
    public BaseResult getByIndex(String idIndex) {
        EtlIndexShowVO pageVO = null;
        if(!StringUtils.isEmpty(idIndex)) {
            pageVO = etlIndexsqlService.getByIndex(idIndex);
        }
        return new BaseResult(CommonResultConstant.SUCCESS, pageVO);
    }

    @ApiOperation(value="保存")
    @ApiImplicitParam(name="EtlIndexSqlVO", value="实体", paramType="body", required=true, dataType="EtlIndexSqlVO")
    @RequestMapping(value="save", method=RequestMethod.POST)
    public BaseResult save(@RequestBody EtlIndexSqlVO vo)  {
        etlIndexsqlService.save(vo);
        return new BaseResult(CommonResultConstant.SUCCESS, null);
    }

    @ApiOperation(value="详情")
    @ApiImplicitParam(name="idIndexsql", value="主键", paramType="query", required=true, dataType="String")
    @RequestMapping(value="getById", method=RequestMethod.GET)
    public BaseResult getById(String idIndexsql, HttpServletRequest request) throws BaseException {
        if(StringUtils.isEmpty(idIndexsql)){
            throw new BaseException("请选择要编辑的项");
        }
        EtlIndexsql etlIndexsql = etlIndexsqlService.getById(idIndexsql);
        return new BaseResult(CommonResultConstant.SUCCESS, etlIndexsql);
    }

    @ApiOperation(value="修改")
    @ApiImplicitParam(name="etlIndexsql", value="实体", paramType="body", required=true, dataType="EtlIndexsql")
    @RequestMapping(value="update", method=RequestMethod.POST)
    public BaseResult update(@RequestBody EtlIndexsql etlIndexsql, HttpServletRequest request)  {
        int num = etlIndexsqlService.updateByIdSelective(etlIndexsql);
        return new BaseResult(CommonResultConstant.SUCCESS, num);
    }

    @ApiOperation(value="根据主键删除")
    @ApiImplicitParam(name="idIndexsql", value="主键", paramType="query", required=true, dataType="String")
    @RequestMapping(value="delete", method=RequestMethod.GET)
    public BaseResult delete(String idIndexsql, HttpServletRequest request) throws BaseException {
        if(StringUtils.isEmpty(idIndexsql)){
            throw new BaseException("请选择要删除的项");
        }
        int num = etlIndexsqlService.deleteById(idIndexsql);
        return new BaseResult(CommonResultConstant.SUCCESS, num);
    }



}
